import {arrayToMap, deleteSql, insertSql, objectToMap, selectSql, updateSql} from "../util/sqlUtils";
import {UserRoles} from "../util/Constants";
import {Plan} from "../sql/domin";

export class PlanMapper{

    private static tableName = 'dept_output_plan'

    public static selectPlanList(){
        return selectSql(this.tableName)
    }

    public static selectPlanListByRole(role:UserRoles){
        let sql = ''
        switch (role){
            case UserRoles.BZZ:
                // 班组长查询2天内的
                sql = "where date('now','+2 day') >= date(planTime)"
                break
            case UserRoles.CZY:
                // 操作员查询1天内的
                sql = "where date('now','+1 day') >= date(planTime)"
                break
            case UserRoles.HEAD:
                // 主任查看当月的
                sql = "where 1=1"
                break
        }
        return selectSql(this.tableName,sql)
    }

    public static selectPlanById(id:number){
        return selectSql(this.tableName,new Map([
            ['id',id]
        ]))
    }

    public static deletePlanByRole(role:UserRoles){
        return deleteSql(this.tableName,'where 1=1')
    }

    public static updatePlan(plan:Plan){
        return updateSql(this.tableName,objectToMap(plan),'where id = '+plan.id)
    }

    public static insertPlanList(plans:Plan[]){
        return insertSql(this.tableName,arrayToMap(plans))
    }

    public static insertPlan(plans:Plan){
        return insertSql(this.tableName,objectToMap(plans))
    }

}
